#ifndef VBOX_INCLUDE_VBOX_APIC_H
#define VBOX_INCLUDE_VBOX_APIC_H
#ifndef RT_WITHOUT_PRAGMA_ONCE
#pragma once
#endif

#include <iprt/types.h>
#include <iprt/x86.h>

#define APIC_REG_VERSION 0x0030
#define APIC_REG_VERSION_GET_VER(u32) (u32 & 0xff)
#define APIC_REG_VERSION_GET_MAX_LVT(u32) ((u32 & 0xff0000) >> 16)

// defines according to figure 10-8 of the Intel Software Developers Manula Vol 3A
#define APIC_REG_LVT_LINT0 0x0350


// TODO: a lot of defines

typedef enum XAPICDESTFORMAT
{
    XAPICDESTFORMAT_FLAT = 0xf,
    XAPICDESTFORMAT_CLUSTER = 0
} XAPICDESTFORMAT;

typedef enum XAPICTIMERMODE
{
    XAPICTIMERMODE_ONESHOT = XAPIC_TIMER_MODE_ONESHOT, // oneshot
    // TODO: fucking this enum
} XAPICTIMERMODE;

// TODO: enums defines

DECLINLINE(uint32_t) ApicRegRead(void* pvBase, uint32_t offReg)
{
    return *(const volatile uint32_t*)((uintptr_t) pvBase + offReg);
}

#ifdef IPRT_INCLUDE_asm_amd64_x86_h // TODO: rename
DECLINLINE(uint32_t) ApicX2RegRead32(uint32_t offReg)
{
    return ASMRdMsr((offReg >> 4) + MSR_IA32_X2APIC_START);
}
#endif

#endif // header file protect
